package org.jeecg.common.util;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.List;

public class ErrorUtils {
    public ErrorUtils() {
    }

    public static String getErrorMessages(BindingResult errors) {
        List<FieldError> errorList = errors.getFieldErrors();
        String errorMessage = "";

        for(int i = 0; i < errorList.size(); ++i) {
            if (i > 0) {
                errorMessage = errorMessage + ";";
            }

            errorMessage = errorMessage + ((FieldError)errorList.get(i)).getDefaultMessage();
        }

        return errorMessage;
    }
}
